<?php 


require "../common/Curl.php";

/**
 *	https=>//open.esign.cn/doc/detail?id=opendoc%2Fpaas_api%2Fsgv49u&namespace=opendoc%2Fpaas_api
 * 	电子签名SaaS API非标版
 * 	流程签署区----接口顺序排列封装
 *  使用请求签名鉴权方式
 *  下一个------------------ 流程签署人 sign5.php
 */



//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/**
 * [addPlatformSign 添加平台方自动盖章签署区]
 * @param [type] $aaaa   [description]
 * @param [type] $flowId [description]
 * @param [type] $appId  [description]
 * @param [type] $secret [description]
 * @param [type] $url    [description]
 */
function addPlatformSign($aaaa,$flowId,$appId,$secret,$url){
	$urlss = $url."/v1/signflows/".$flowId."/signfields/platformSign";
	$head_url = "/v1/signflows/".$flowId."/signfields/platformSign";
    $data = json_decode($aaaa,true);
    $res = json_encode($data);
    $header = getHeader($data,"POST",$head_url,$appId,$secret,$url);
    $result = sendHttp($method="POST",$urlss,$header,$res);
    return $result;
}
// $flowId = "9a1f67f7f8094d5bbe24ff6927ba4e03";
// $aaaa = '{
//     "signfields":[
//         {
//             "fileId":"fe7df2f477d649c18ebcfdfffeba253d",
//             "order":1,
//             "posBean":{
//                 "posPage":"1",
//                 "posX":158.72531,
//                 "posY":431.05658
//             },
//             "sealId":"bcd7ffd9-5caf-4342-bd1c-02257229ccd5",
//             "signType":1
//         }
//     ]
// }';
// $a = addPlatformSign($aaaa,$flowId,$appId,$secret,$url);
// var_dump($a);die;


//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/**
 * [addAutoSign 添加签署方自动盖章签署区]
 * @param [type] $aaaa   [description]
 * @param [type] $flowId [description]
 * @param [type] $appId  [description]
 * @param [type] $secret [description]
 * @param [type] $url    [description]
 */
function addAutoSign($aaaa,$flowId,$appId,$secret,$url){
	$urlss = $url."/v1/signflows/".$flowId."/signfields/autoSign";
	$head_url = "/v1/signflows/".$flowId."/signfields/autoSign";
    $data = json_decode($aaaa,true);
    $res = json_encode($data);
    $header = getHeader($data,"POST",$head_url,$appId,$secret,$url);
    $result = sendHttp($method="POST",$urlss,$header,$res);
    return $result;
}
// $flowId = "9a1f67f7f8094d5bbe24ff6927ba4e03";
// $aaaa = '{
//     "signfields":[
//         {
//             "fileId":"fe7df2f477d649c18ebcfdfffeba253d",
//             "authorizedAccountId":"2c7de24aff3340f5b944ebac49545b8e",
//             "order":1,
//             "posBean":{
//                 "posPage":"1",
//                 "posX":158.72531,
//                 "posY":431.05658
//             },
//             "sealId":"bcd7ffd9-5caf-4342-bd1c-02257229ccd5",
//             "signType":1
//         }
//     ]
// }';
// $a = addAutoSign($aaaa,$flowId,$appId,$secret,$url);
// var_dump($a);die;


//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/**
 * [addHandSign 添加签署方手动盖章签署区]
 * @param [type] $aaaa   [description]
 * @param [type] $flowId [description]
 * @param [type] $appId  [description]
 * @param [type] $secret [description]
 * @param [type] $url    [description]
 */
function addHandSign($aaaa,$flowId,$appId,$secret,$url){
	$urlss = $url."/v1/signflows/".$flowId."/signfields/handSign";
	$head_url = "/v1/signflows/".$flowId."/signfields/handSign";
    $data = json_decode($aaaa,true);
    $res = json_encode($data);
    $header = getHeader($data,"POST",$head_url,$appId,$secret,$url);
    $result = sendHttp($method="POST",$urlss,$header,$res);
    return $result;
}
// $flowId = "9a1f67f7f8094d5bbe24ff6927ba4e03";
// $aaaa = '{
//     "signfields":[
//         {
//             "signerAccountId":"faea8237c61a4fdea864ee8d7621e14f",
//             "authorizedAccountId":"2c7de24aff3340f5b944ebac49545b8e",
//             "actorIndentityType":2,
//             "fileId":"fe7df2f477d649c18ebcfdfffeba253d",
//             "order":1,
//             "assignedPosbean":true,
//             "posBean":{
//                 "posPage":"1",
//                 "posX":158.72531,
//                 "posY":431.05658
//             },
//             "sealType":"0",
//             "sealId":"0123",
//             "signType":1
//         }
//     ]
// }';
// $a = addHandSign($aaaa,$flowId,$appId,$secret,$url);
// var_dump($a);die;

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/**
 * [selectSignfields 查询签署区列表]
 * @param  [type] $flowId       [description]
 * @param  [type] $accountId    [description]
 * @param  [type] $signfieldIds [description]
 * @param  [type] $appId        [description]
 * @param  [type] $secret       [description]
 * @param  [type] $url          [description]
 * @return [type]               [description]
 */
function selectSignfields($flowId,$accountId,$signfieldIds,$appId,$secret,$url){
	$urlss = $url."/v1/signflows/".$flowId."/signfields?accountId=".$accountId;
	$head_url = "/v1/signflows/".$flowId."/signfields?accountId=".$accountId;
	$data =[];
    $res = json_encode($data);
    $header = getHeader($data,"GET",$head_url,$appId,$secret);
    $result = sendHttp($method="GET",$urlss,$header,$res);
    return $result;
}
// $flowId = "9a1f67f7f8094d5bbe24ff6927ba4e03";
// $accountId = "9a1f67f7f8094d5bbe24ff6927ba4e03";
// $a = selectSignfields($flowId,$accountId,$signfieldIds,$appId,$secret,$url);
// var_dump($a);die;

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/**
 * [deleteFields 删除签署区]
 * @param  [type] $flowId       [description]
 * @param  [type] $signfieldIds [description]
 * @param  [type] $appId        [description]
 * @param  [type] $secret       [description]
 * @param  [type] $url          [description]
 * @return [type]               [description]
 */
function deleteFields($flowId,$signfieldIds,$appId,$secret,$url){
	$urlss = $url."/v1/signflows/".$flowId."/signfields?signfieldIds=".$signfieldIds;
	$head_url = "/v1/signflows/".$flowId."/signfields?signfieldIds=".$signfieldIds;
	$data =[];
    $res = json_encode($data);
    $header = getHeader($data,"DELETE",$head_url,$appId,$secret);
    $result = sendHttp($method="DELETE",$urlss,$header,$res);
    return $result;
}
// $flowId = "9a1f67f7f8094d5bbe24ff6927ba4e03";
// $signfieldIds = '01e50a9cedb74493a2d320b4f4732a29,ee2da3b8cc60422e8076ec55489fb0da';
// $a = deleteFields($flowId,$signfieldIds,$appId,$secret,$url);
// var_dump($a);die;





